/// 选择基础类
abstract class ChoiceBean {
  /// 是否选中
  bool _isChecked = false;

  ///获取id字段
  String getId();

  ///获取显示的名称字段
  String getShowName();

  ///设置是否已经选择
  setIsChecked(bool isChecked) => _isChecked = isChecked;

  /// 是否已经选择
  bool getIsChecked() => _isChecked;
}

/// 简单的选择基础类
class SimpleChoiceBean<T> extends ChoiceBean {
  SimpleChoiceBean({required this.id, required this.value, bool isChecked = false}) {
    setIsChecked(isChecked);
  }

  final String? id;
  final T value;

  @override
  String toString() {
    return value.toString();
  }

  @override
  String getId() {
    return id ?? '';
  }

  @override
  String getShowName() {
    return toString();
  }
}

abstract class TreeChoiceIface {
  List<TreeChoiceIface>? get treeChildren;
  String get treeId;
  String get treeName;

  @override
  String toString() {
    return 'TreeChoiceIface{id: $treeId, name: $treeName}';
  }
}

class SimpleTree implements TreeChoiceIface {
  const SimpleTree({
    required this.treeId,
    required this.treeName,
    this.treeChildren,
  });

  @override
  final String treeId;
  @override
  final String treeName;
  @override
  final List<TreeChoiceIface>? treeChildren;
}

extension TreeChoiceIfaceX on TreeChoiceIface {
  int get depth {
    int depth = 0;
    if (treeChildren != null) {
      for (final child in treeChildren ?? <TreeChoiceIface>[]) {
        depth = depth > child.depth ? depth : child.depth;
      }
    }
    return depth + 1;
  }
}
